package com.cmccgz.udacs_landlord_webapp.base;

import android.content.Context;

import com.cmccgz.baselibrary.utils.FileUtils;
import com.cmccgz.udacs_landlord_webapp.bean.AccreditCardBean;
import com.cmccgz.udacs_landlord_webapp.bean.AccreditDetailBean;
import com.cmccgz.udacs_landlord_webapp.bean.AppInfo;
import com.cmccgz.udacs_landlord_webapp.bean.BuildingCountBean;
import com.cmccgz.udacs_landlord_webapp.bean.CardBean;
import com.cmccgz.udacs_landlord_webapp.bean.CardDetail;
import com.cmccgz.udacs_landlord_webapp.bean.CardInfo;
import com.cmccgz.udacs_landlord_webapp.bean.CardMsg;
import com.cmccgz.udacs_landlord_webapp.bean.Device;
import com.cmccgz.udacs_landlord_webapp.bean.DeviceInfoBean;
import com.cmccgz.udacs_landlord_webapp.bean.ExchangeCard;
import com.cmccgz.udacs_landlord_webapp.bean.FileResultBean;
import com.cmccgz.udacs_landlord_webapp.bean.HouseListDataBean;
import com.cmccgz.udacs_landlord_webapp.bean.HousePeopleBean;
import com.cmccgz.udacs_landlord_webapp.bean.LoginInfo;
import com.cmccgz.udacs_landlord_webapp.bean.Media;
import com.cmccgz.udacs_landlord_webapp.bean.MobileBean;
import com.cmccgz.udacs_landlord_webapp.bean.Person;
import com.cmccgz.udacs_landlord_webapp.bean.PushRequestBean;
import com.cmccgz.udacs_landlord_webapp.bean.RecordDetail;
import com.cmccgz.udacs_landlord_webapp.bean.RenterBean;
import com.cmccgz.udacs_landlord_webapp.bean.RequestBean;
import com.cmccgz.udacs_landlord_webapp.bean.ResultBean;
import com.cmccgz.udacs_landlord_webapp.bean.UnlockRecord;
import com.cmccgz.udacs_landlord_webapp.bean.UserInfo;
import com.cmccgz.udacs_landlord_webapp.bean.WarningDetail;
import com.cmccgz.udacs_landlord_webapp.bean.WarningItem;

import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * @author: Huang
 * @Descripion:
 * @date 2017/5/26 09:18
 */

public class ApiService {

//    private static String baseUrl = "http://udacs-dev.gmcciot.com/app-api/android/";
//    private static String baseUrl = "http://udacs-staging.gmcciot.com/app-api/android/";

    private static OkHttpClient client;

    private static Retrofit retrofit;

    private static API service;
    private static Observable.Transformer schedulersTransformer = new Observable.Transformer() {
        @Override
        public Object call(Object o) {
            return ((Observable) o).subscribeOn(Schedulers.newThread())
                    .observeOn(AndroidSchedulers.mainThread());
        }
    };

    private static <T> Observable.Transformer<T, T> applySchedulers() {
        return (Observable.Transformer<T, T>) schedulersTransformer;
    }

    /**
     * 排空，赋值
     */
    private static void checkNull() {
        if (client == null) {
            client = new OkHttpClient()
                    .newBuilder()
                    .readTimeout(20, TimeUnit.SECONDS)
                    .connectTimeout(20, TimeUnit.SECONDS)
                    .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                    .build();
        }
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(AppConfig.getBaseUrl())
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(client)
                    .build();
        }
        if (service == null) {
            service = retrofit.create(API.class);
        }
    }

    public static void init() {
        client = null;
        retrofit = null;
        service = null;
        checkNull();
    }

    /**
     * 登录
     *
     * @param mobile   手机号
     * @param password 密码
     * @return
     */
    public static Observable<ResultBean<LoginInfo>> login(String mobile, String password, String type) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance(), mobile)
                .addReqParams("type", type)
                .addReqParams("mobile", mobile)
                .addReqParams("password", password);
        return service.login(requestBean);
    }

    /**
     * 获取房屋/楼栋列表
     *
     * @param type
     * @param qWord
     * @param oCond
     * @param page
     * @return
     */
    public static Observable<ResultBean<List<HouseListDataBean>>> getHouseList(String type, String qWord, String oCond, int page) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", AppConfig.getMobile(GlobalContext.getInstance()))
                .addReqParams("type", type)
                .addReqParams("q_word", qWord)
                .addReqParams("o_cond", oCond)
                .addReqParams("page", String.valueOf(page));
        return service.getHouseList(requestBean)
                .compose(ApiService.<ResultBean<List<HouseListDataBean>>>applySchedulers());
    }

    /**
     * 获取房屋下租客详情
     *
     * @param house_id
     * @return
     */
    public static Observable<ResultBean<List<HousePeopleBean>>> getHouseDetail(String house_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", AppConfig.getMobile(GlobalContext.getInstance()))
                .addReqParams("house_id", house_id);
        return service.getHouseDetail(requestBean).compose(ApiService.<ResultBean<List<HousePeopleBean>>>applySchedulers());
    }

    /**
     * 换房
     *
     * @param mobileList
     * @param old_house_id
     * @param new_house_id
     * @return
     */
    public static Observable<ResultBean> houseChange(List<MobileBean> mobileList, String old_house_id, String new_house_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("users", mobileList)
                .addReqParams("old_house_id", old_house_id)
                .addReqParams("new_house_id", new_house_id);
        return service.houseChange(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }

    /**
     * 退房
     *
     * @param mobileList
     * @param house_id
     * @return
     */
    public static Observable<ResultBean> checkOut(List<MobileBean> mobileList, String house_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("users", mobileList)
                .addReqParams("house_id", house_id);
        return service.checkOut(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }

    /**
     * 房屋统计
     *
     * @param building_id
     * @return
     */
    public static Observable<ResultBean<List<BuildingCountBean>>> buildingCount(String building_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", AppConfig.getMobile(GlobalContext.getInstance()))
                .addReqParams("building_id", building_id);
        return service.buildingCountDetail(requestBean).compose(ApiService.<ResultBean<List<BuildingCountBean>>>applySchedulers());
    }

    /**
     * 获取用户信息
     *
     * @param mobile
     * @return
     */
    public static Observable<ResultBean<UserInfo>> getUserInfo(String mobile) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile);
        return service.getUserInfo(requestBean);
    }

    /**
     * 获取用户信息
     *
     * @param mobile
     * @return
     */
    public static Observable<ResultBean> changePassword(String mobile, String old_pd, String new_pd) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("old_pd", old_pd)
                .addReqParams("new_pd", new_pd);
        return service.changePassword(requestBean);
    }

    /**
     * 获取设备列表
     *
     * @param mobile
     * @return
     */
    public static Observable<ResultBean<List<Device>>> getDevices(String mobile) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile);
        return service.getDevices(requestBean);
    }

    /**
     * 远程开门
     *
     * @param mobile
     * @return
     */
    public static Observable<ResultBean> openDoor(String mobile, String deviceId) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile).addReqParams("device_id", deviceId);
        return service.openDoor(requestBean);
    }

    /**
     * 获取进出记录
     * @param q_word
     * @param device_id
     * @param start_date
     * @param end_date
     * @param page
     * @return
     */
    public static Observable<ResultBean<List<UnlockRecord>>> getUnlockRecord(String q_word, String device_id,String start_date,String end_date, int page) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", AppConfig.getMobile(GlobalContext.getInstance()))
                .addReqParams("q_word", q_word)
                .addReqParams("device_id", device_id)
                .addReqParams("start_date", start_date)
                .addReqParams("end_date", end_date)
                .addReqParams("page", String.valueOf(page));
        return service.getUnlockRecord(requestBean).compose(ApiService.<ResultBean<List<UnlockRecord>>>applySchedulers());
    }

    /**
     * 修改用户信息
     *
     * @param mobile
     * @return
     */
    public static Observable<ResultBean> changeUserInfo(String mobile, String nick_name, String head_id, String sex, String age) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("nick_name", nick_name)
                .addReqParams("head_id", head_id)
                .addReqParams("sex", sex)
                .addReqParams("age", age);
        return service.changeUserInfo(requestBean).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread());
    }

    /**
     * 5.1获取租客列表
     */
    public static Observable<ResultBean<List<RenterBean>>> getUserList(String mobile, String q_word,
                                                                       String o_cond, String page) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("q_word", q_word)
                .addReqParams("o_cond", o_cond)
                .addReqParams("page", page);
        return service.getUserList(requestBean);
    }

    /**
     * 5.2 获取租客卡片详情
     */
    public static Observable<ResultBean<CardMsg>> getCardDetail(String mobile, String house_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("house_id", house_id);
        return service.getCardDetail(requestBean);
    }

    /**
     * 5.3 新增卡片
     */
    public static Observable<ResultBean<String>> newCard(String user_mobile, String house_id, List<CardBean> cards) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("user_mobile", user_mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("cards", cards);
        return service.newCard(requestBean);
    }

    /**
     * 5.4 更换卡片
     */
    public static Observable<ResultBean<String>> changeCard(String user_mobile, String house_id, List<ExchangeCard> cards) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("user_mobile", user_mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("cards", cards);
        return service.changeCard(requestBean);
    }

    /**
     * 5.5 销卡
     */
    public static Observable<ResultBean<String>> deleteCard(String user_mobile, String house_id, List<CardBean> cards) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("user_mobile", user_mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("cards", cards);
        return service.deleteCard(requestBean);
    }

    /**
     * 5.6	提交租客卡状态变更
     */
    public static Observable<ResultBean<String>> cardStatusChange(String user_mobile, String house_id, List<CardBean> cards) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("user_mobile", user_mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("cards", cards);
        return service.cardStatusChange(requestBean);
    }

    /**
     * 5.7	更改租客卡有效时间
     */
    public static Observable<ResultBean<String>> dateChange(String user_mobile, String house_id, List<CardBean> cards) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("user_mobile", user_mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("cards", cards);
        return service.dateChange(requestBean);
    }

    /**
     * 7.1 开卡授权
     *
     * @return
     */
    public static Observable<ResultBean> accreditCard(AccreditCardBean bean) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", bean.getMobile())
                .addReqParams("user_mobile", bean.getUser_mobile())
                .addReqParams("user_name", bean.getUser_name())
                .addReqParams("sex", bean.getSex())
                .addReqParams("id_card", bean.getId_card())
                .addReqParams("user_nation", bean.getUser_nation())
                .addReqParams("user_bir", bean.getUser_bir())
                .addReqParams("house_id", bean.getHouse_id())
                .addReqParams("house_end_time", bean.getHouse_end_time());
        return service.accreditCard(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }

    public static Observable<ResultBean> changeCardState(String user_mobile, String house_id, List<CardDetail> cards) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("user_mobile", user_mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("cards", cards);
        return service.changeCardState(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }

    public static Observable<FileResultBean> upload(String fileUrl) {
        checkNull();
        Context context = GlobalContext.getInstance();
        File file = new File(fileUrl);
        String signature = "fromid:" + AppConfig.getMobile(context)
                + ",imsi:" + AppConfig.getIMSI(context) + ",imei:" + AppConfig.getIMEI(context) + ",token:" + AppConfig.getToken(context);
        String toUser = "type:2,id:" + AppConfig.getMobile(context);

        RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody.Part body = MultipartBody.Part.createFormData("media", file.getName(), requestFile);
        RequestBody type = RequestBody.create(MediaType.parse("multipart/form-data"), "1");
        RequestBody mediaDetail = RequestBody.create(MediaType.parse("multipart/form-data"), "");
        return service.upload(RequestBody.create(MediaType.parse("multipart/form-data"), signature),
                RequestBody.create(MediaType.parse("multipart/form-data"), toUser),
                type, mediaDetail, body).compose(ApiService.<FileResultBean>applySchedulers());
    }

    public static Observable<ResultBean<List<DeviceInfoBean>>> deviceSync() {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", AppConfig.getMobile(GlobalContext.getInstance()));

        return service.deviceSync(requestBean).compose(ApiService.<ResultBean<List<DeviceInfoBean>>>applySchedulers());
    }

    /**
     * 获取验证码
     *
     * @param mobile
     * @param type   功能类型：0:登录，1:忘记密码
     * @return
     */
    public static Observable<ResultBean> getSms(String mobile, String type) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance(), mobile)
                .addReqParams("type", type)
                .addReqParams("mobile", mobile);

        return service.getSms(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }

    /**
     * 获取验证码
     *
     * @param mobile
     * @param new_pd 功能类型：0:登录，1:忘记密码
     * @return
     */
    public static Observable<ResultBean> resetPD(String mobile, String new_pd, String sms_key) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance(), mobile)
                .addReqParams("new_pd", new_pd)
                .addReqParams("sms_key", sms_key)
                .addReqParams("mobile", mobile);

        return service.resetPD(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }

    /**
     * 获得访客请求授权详情
     *
     * @param mobile
     * @param requestId
     * @return
     */
    public static Observable<ResultBean<AccreditDetailBean>> getRequestDetail(String mobile, String requestId) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance(), mobile)
                .addReqParams("request_id", requestId)
                .addReqParams("mobile", mobile);

        return service.getRequestDetail(requestBean).compose(ApiService.<ResultBean<AccreditDetailBean>>applySchedulers());
    }

    /**
     * 处理访客请求授权
     *
     * @param requestId
     * @param isAgree
     * @param reason
     * @param deviceId
     * @param startTime
     * @param endTime
     * @param times
     * @return
     */
    public static Observable<ResultBean> handleVisitorRequest(String requestId, String isAgree, String reason, String deviceId, String startTime, String endTime, String times) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("request_id", requestId)
                .addReqParams("is_agree", isAgree)
                .addReqParams("reason", reason)
                .addReqParams("device_id", deviceId)
                .addReqParams("start_time", startTime)
                .addReqParams("end_time", endTime)
                .addReqParams("times", times);
        return service.handleVisitorRequest(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }

    /**
     * 获取APP版本信息
     * @param appId
     * @return
     */
    public static Observable<ResultBean<AppInfo>> getAppInfo(String appId) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("app_id", appId);
        return service.getAppInfo(requestBean).compose(ApiService.<ResultBean<AppInfo>>applySchedulers());
    }

    /**
     *
     * @param q_word
     * @param o_cond
     * @param page
     * @return
     */
    public static Observable<ResultBean<List<PushRequestBean>>> getRequestList(String q_word, String o_cond, String page) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", AppConfig.getMobile(GlobalContext.getInstance()))
                .addReqParams("q_word",q_word)
                .addReqParams("o_cond", o_cond)
                .addReqParams("page", page);
        return service.getRequestList(requestBean).compose(ApiService.<ResultBean<List<PushRequestBean>>>applySchedulers());
    }

    public static Observable<ResultBean<List<DeviceInfoBean>>> getDevicesStatus() {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", AppConfig.getMobile(GlobalContext.getInstance()));

        return service.getDevicesStatus(requestBean).compose(ApiService.<ResultBean<List<DeviceInfoBean>>>applySchedulers());
    }

    public static Observable<ResultBean<List<WarningItem>>> getWarningList(String q_word,String o_cond,String f_cond,String page) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("q_word", q_word)
                .addReqParams("o_cond", o_cond)
                .addReqParams("f_cond", f_cond)
                .addReqParams("page", page)
                .addReqParams("mobile", AppConfig.getMobile(GlobalContext.getInstance()));

        return service.getWarningList(requestBean).compose(ApiService.<ResultBean<List<WarningItem>>>applySchedulers());
    }

    public static Observable<ResultBean<WarningDetail>> getWarningDetail(String w_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("w_id", w_id);
        return service.getWarningDetail(requestBean).compose(ApiService.<ResultBean<WarningDetail>>applySchedulers());
    }

    public static Observable<ResultBean> createWarning(String c_timestamp,String c_phone,String desc,String device_id,List<Media> media) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("c_timestamp", c_timestamp)
                .addReqParams("c_phone", c_phone)
                .addReqParams("desc", desc)
                .addReqParams("device_id", device_id)
                .addReqParams("media", media);
        return service.createWarning(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }

    public static Observable<ResultBean> deleWarning(String w_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("w_id", w_id);
        return service.deleWarning(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }
    public static Observable<ResultBean> editWarning(String w_id,String desc,List<Media> media) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("w_id", w_id)
                .addReqParams("desc", desc)
                .addReqParams("media", media);
        return service.editWarning(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }
    public static Observable<ResultBean> dealWarning(String w_id,String d_phone,String d_result,String d_type,String sn) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("w_id", w_id)
                .addReqParams("d_phone", d_phone)
                .addReqParams("d_result", d_result)
                .addReqParams("d_type", d_type)
                .addReqParams("sn", sn);
        return service.dealWarnig(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }
    public static Observable<ResultBean> confirmWarning(String w_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("w_id", w_id);
        return service.confirmWarning(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }
    public static Observable<ResultBean> rejectWarning(String w_id,String desc,List<Media> media) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("w_id", w_id)
                .addReqParams("desc", desc)
                .addReqParams("media", media);
        return service.rejectWarning(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }
    public static Observable<ResultBean<RecordDetail>> getRecDetail(String id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("id", id);
        return service.getRecDetail(requestBean).compose(ApiService.<ResultBean<RecordDetail>>applySchedulers());
    }

    /**
     * 下载文件
     * @param url 网络url
     * @param outFile 本地目标文件
     * @return
     */
    public static Observable<Boolean> downFile(String url, final File outFile) {
        checkNull();
        return service.downFile(url).subscribeOn(Schedulers.io()).unsubscribeOn(Schedulers.io())
                .map(new Func1<ResponseBody, Boolean>() {
                    @Override
                    public Boolean call(ResponseBody responseBody) {
                        try {
                            FileUtils.writeFile(responseBody.byteStream(), outFile);
                        } catch (Exception e) {
                            e.printStackTrace();
                            return false;
                        }
                        return true;
                    }
                }).compose(ApiService.<Boolean>applySchedulers());
    }
    public static Observable<ResultBean<List<Person>>> getRenterList(String mobile,String house_id) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("house_id", house_id);
        return service.getRenterList(requestBean).compose(ApiService.<ResultBean<List<Person>>>applySchedulers());
    }
    public static Observable<ResultBean> addRenter(String mobile,String house_id,
                                                   String user_mobile,String user_name,
                                                   String sex,String id_card,
                                                   String user_nation,String address,
                                                   String user_bir,String house_no,String sms_key) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("user_mobile", user_mobile)
                .addReqParams("user_name", user_name)
                .addReqParams("sex", sex)
                .addReqParams("id_card", id_card)
                .addReqParams("user_nation", user_nation)
                .addReqParams("address", address)
                .addReqParams("user_bir", user_bir)
                .addReqParams("house_no", house_no)
                .addReqParams("sms_key", sms_key);
        return service.addRenter(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }
    public static Observable<ResultBean<CardInfo>> getCardNo(String mobile, String house_id, String charge_time) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("charge_time", charge_time);
        return service.getCardNo(requestBean).compose(ApiService.<ResultBean<CardInfo>>applySchedulers());
    }
    public static Observable<ResultBean> addCard(String mobile, String house_id, String uuid, String card_type) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("uuid", uuid)
                .addReqParams("card_type", card_type);
        return service.addCard(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }
    public static Observable<ResultBean> appAccredit(String mobile, String house_id, String house_end_time,
                                                     String user_id, List<CardInfo> card_list, String app_open) {
        checkNull();
        RequestBean requestBean = RequestBean.instance(GlobalContext.getInstance())
                .addReqParams("mobile", mobile)
                .addReqParams("house_id", house_id)
                .addReqParams("house_end_time", house_end_time)
                .addReqParams("user_id", user_id)
                .addReqParams("card_list", card_list)
                .addReqParams("app_open", app_open);
        return service.appAccredit(requestBean).compose(ApiService.<ResultBean>applySchedulers());
    }
}